<template>
  <!-- 支付密码 -->
  <el-dialog
    v-model="dialogVisible"
    title="支付密码"
    width="20%"
    :before-close="handleClose"
  >
    <el-row :gutter="24">
      <el-col :span="24">
        <c-payment-code
          v-model="code"
          type="password"
          :disabled="loading"
          @update:modelValue="onPaymentCode"
        />
      </el-col>
    </el-row>
  </el-dialog>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import cPaymentCode from "@/components/Form/PaymentCode.vue";
import { ElMessage } from "element-plus";
const props = defineProps({
  type: {
    type: Number,
    default: 0, // 0 出口订单费用  1 其他费用
  },
});
const { proxy } = getCurrentInstance();
const emits = defineEmits(["change"]);
const code = ref("");
const dialogVisible = ref(false);
const loading = ref(false);
const ids = ref([]);
const onPaymentCode = async (num) => {
  if (num.length >= 6) {
    try {
      loading.value = true;
      await proxy.$post({ url: "/sellerInfo/checkPay", data: num });
      let balanceUrl = "/sellerBill/balance";
      if (props.type === 1) {
        balanceUrl = "/SellerBillExtend/balance";
      }
      await proxy.$post({ url: balanceUrl, data: ids.value });
      ElMessage.success("操作成功");
      emits("change");
      handleClose();
      loading.value = false;
    } catch (error) {
      code.value = "";
      loading.value = false;
    }
  }
};
const handleOpen = async (multiples) => {
  code.value = "";
  ids.value = multiples.map((x) => x.id);
  dialogVisible.value = true;
};
const handleClose = () => {
  dialogVisible.value = false;
};
defineExpose({
  handleOpen,
});
</script>

